<style type="text/css">
    .useradd {
        margin: 0 20px;
    }

    .useradd label {
        display: block;
        margin: 1em auto;
    }
    .userroletree{
        display:none;
    }
    .userroletree .rolename{
        cursor:pointer;
    }
</style>
<script type="text/javascript">
    LC.initToolbar({
        'new': LC.S.tools.toolNew,
        'save': LC.S.tools.toolSave,
        'saveNew': LC.S.tools.toolSaveNew,
        'saveClose': LC.S.tools.toolSaveClose,
        'cancel':LC.S.tools.toolCannel
    });
    $(document).ready(function () {
        $('.userrole').button();
        var roleaddtree=$('.useradd .userroletree').jTree();
        roleaddtree.showAll();
        dialog('.userroletree',{
            autoOpen: false,
            modal:true,
            title:"选择用户角色"
        });
    });
    function choseRole(_this){
        $('.userrole').children().text($(_this).text());
        $('input[name=roleId]').val($(_this).parent().parent().attr('id'));
        $('.userroletree').dialog('close')
    }
    function userNameCheck(){
        if(checkForm($('.useradd input[name=userName]'))) {
            var userName = $('.useradd input[name=userName]').val();
            $.getJSON('system/user.action?act=add&type=userName&userName=' + userName,
                function (json) {
                    if(json.count>0){
                        alert('该用户名已经存在！');
                        setTimeout("$('.useradd input[name=userName]').select()",100);
                    }
                });
        }
    }
</script>
<div class="pannelAdd useradd">
    <div class="group">
        <div class="label">帐号名：</div>
        <div class="value"><input type="text" name="userName" regx="${check.userName}" onchange="userNameCheck()" /></div>
    </div>
    <div class="group">
        <div class="label">密　码：</div>
        <div class="value"><input type="password" name="password" md5/></div>
    </div>
    <div class="group">
        <div class="label">姓　名：</div>
        <div class="value"><input type="text" name="name" regx="${check.name}"/></div>
    </div>
    <div class="group">
        <div class="label">角　色：</div>
        <div class="value">
            <input type="hidden" name="roleId" value=""/>
            <span class="userrole" onClick="$('.userroletree').dialog('open')" title="点击选择角色">未设置用户角色</span>
        </div>
    </div>
    <div class="group">
        <div class="label">备　注：</div>
        <div class="value"><textarea name="notes" isnull></textarea></div>
    </div>
    <div class="userroletree">
    <#list roles as m>
        <div id="${m._id}" pid="${m.parentid}">
            <span class="rolename" title="${m.notes!""}">
                <span class="icon-user2"></span>
                <span class="name" onClick="choseRole(this)">${m.name}</span>
            </span>
        </div>
    </#list>
    </div>
</div>